#
# a generic makefile for a building a single executable 
# from one or more C source files
#
# it uses makedepend, so run 'make depend' once first (and
# again anytime you change #includes). it will spit out 
# some errors about not being able to find some standard .h
# files, which you can ignore. If it cannot find your .h files, 
# however, you need to fix the makefile variable definitions.
#
# 'make depend' auto generate .o dependencies to end of makefile
#
# 'make'  builds the myprog executable
# 'make clean' removes all files that can be rebuilt
#
####################################################################

# makefile variables, some or all may need to be changed 
# to build different executables

# define the compiler to use
CC = gcc

# define compiler flags
# -g    adds debugging information to the executable file
# -Wall turns on most, but not all, compiler warnings
CFLAGS = -g -Wall  

# define any libraries that need to be linked with executable
# -L specifies a library directory (/usr/lib is default)
#    ex.  LFLAGS = -L/home/newhall/lib  
LFLAGS =
# -l specifies the name of a libray to link in
#    ex.  LiBS = -lm  -lreadline        
LIBS = -lreadline

# add to include path all directories containing .h files 
# needed for build 
INCLUDEPATH = -I./ 

# list my program specific header files (not standard ones included)
INCLS = parsecmd.h history.h

# define the .c source files
SRCS = parsecmd.c history.c myshell.c

# define the C object files automatically from $SRCS
# This uses Suffix Replacement within a macro:
#    $(name:string1=string2)
#          For each word in 'name' replace 'string1' with 'string2'
#  Below we are replacing the suffix .c of all words in the macro SRCS
#  with the .o suffix
OBJS = $(SRCS:.c=.o)

# define the name of executable file
TARGET = myshell


.PHONY: depend clean

all: $(TARGET) sleeper inputs

$(TARGET): $(OBJS) 
	$(CC) $(CFLAGS) $(INCLUDEPATH) $(INCLUDES) -o $(TARGET)  $(OBJS) $(LFLAGS) $(LIBS)

sleeper: sleeper.o
	$(CC) $(CFLAGS) -o sleeper  sleeper.o

inputs: inputs.o
	$(CC) $(CFLAGS) -o inputs inputs.o


# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file) 
# (see the gnu make manual section about automatic variables)
.c.o: 
	$(CC) $(CFLAGS) $(INCLUDEPATH) $(INCLUDES) -c $<  -o $@

clean: 
	$(RM) *.o *~ $(TARGET) sleeper inputs

depend: $(SRCS)
	        makedepend $(INCLUDEPATH) $(INCLUDES) $^

# DO NOT DELETE THIS LINE -- make depend needs it

parsecmd.o: /usr/include/stdio.h /usr/include/features.h
parsecmd.o: /usr/include/bits/predefs.h /usr/include/sys/cdefs.h
parsecmd.o: /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h
parsecmd.o: /usr/include/gnu/stubs-64.h /usr/include/bits/types.h
parsecmd.o: /usr/include/bits/typesizes.h /usr/include/libio.h
parsecmd.o: /usr/include/_G_config.h /usr/include/wchar.h
parsecmd.o: /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h
parsecmd.o: /usr/include/string.h /usr/include/xlocale.h
parsecmd.o: /usr/include/stdlib.h /usr/include/bits/waitflags.h
parsecmd.o: /usr/include/bits/waitstatus.h /usr/include/endian.h
parsecmd.o: /usr/include/bits/endian.h /usr/include/bits/byteswap.h
parsecmd.o: /usr/include/sys/types.h /usr/include/time.h
parsecmd.o: /usr/include/sys/select.h /usr/include/bits/select.h
parsecmd.o: /usr/include/bits/sigset.h /usr/include/bits/time.h
parsecmd.o: /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h
parsecmd.o: /usr/include/alloca.h /usr/include/unistd.h
parsecmd.o: /usr/include/bits/posix_opt.h /usr/include/bits/environments.h
parsecmd.o: /usr/include/bits/confname.h /usr/include/getopt.h
parsecmd.o: /usr/include/sys/stat.h /usr/include/bits/stat.h
parsecmd.o: /usr/include/fcntl.h /usr/include/bits/fcntl.h parsecmd.h
history.o: /usr/include/stdlib.h /usr/include/features.h
history.o: /usr/include/bits/predefs.h /usr/include/sys/cdefs.h
history.o: /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h
history.o: /usr/include/gnu/stubs-64.h /usr/include/bits/waitflags.h
history.o: /usr/include/bits/waitstatus.h /usr/include/endian.h
history.o: /usr/include/bits/endian.h /usr/include/bits/byteswap.h
history.o: /usr/include/sys/types.h /usr/include/bits/types.h
history.o: /usr/include/bits/typesizes.h /usr/include/time.h
history.o: /usr/include/sys/select.h /usr/include/bits/select.h
history.o: /usr/include/bits/sigset.h /usr/include/bits/time.h
history.o: /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h
history.o: /usr/include/alloca.h /usr/include/string.h /usr/include/xlocale.h
history.o: history.h
myshell.o: /usr/include/stdlib.h /usr/include/features.h
myshell.o: /usr/include/bits/predefs.h /usr/include/sys/cdefs.h
myshell.o: /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h
myshell.o: /usr/include/gnu/stubs-64.h /usr/include/bits/waitflags.h
myshell.o: /usr/include/bits/waitstatus.h /usr/include/endian.h
myshell.o: /usr/include/bits/endian.h /usr/include/bits/byteswap.h
myshell.o: /usr/include/sys/types.h /usr/include/bits/types.h
myshell.o: /usr/include/bits/typesizes.h /usr/include/time.h
myshell.o: /usr/include/sys/select.h /usr/include/bits/select.h
myshell.o: /usr/include/bits/sigset.h /usr/include/bits/time.h
myshell.o: /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h
myshell.o: /usr/include/alloca.h /usr/include/string.h /usr/include/xlocale.h
myshell.o: /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h
myshell.o: /usr/include/wchar.h /usr/include/bits/stdio_lim.h
myshell.o: /usr/include/bits/sys_errlist.h /usr/include/unistd.h
myshell.o: /usr/include/bits/posix_opt.h /usr/include/bits/environments.h
myshell.o: /usr/include/bits/confname.h /usr/include/getopt.h
myshell.o: /usr/include/sys/wait.h /usr/include/signal.h
myshell.o: /usr/include/bits/signum.h /usr/include/bits/siginfo.h
myshell.o: /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h
myshell.o: /usr/include/bits/sigstack.h /usr/include/sys/ucontext.h
myshell.o: /usr/include/bits/sigthread.h /usr/include/sys/resource.h
myshell.o: /usr/include/bits/resource.h /usr/include/assert.h
myshell.o: /usr/include/readline/readline.h /usr/include/readline/rlstdc.h
myshell.o: /usr/include/readline/rltypedefs.h /usr/include/readline/keymaps.h
myshell.o: /usr/include/readline/chardefs.h /usr/include/ctype.h
myshell.o: /usr/include/readline/tilde.h parsecmd.h history.h
